package com.liusand.controller;

import com.liusand.common.Result;
import com.liusand.dto.OrderDto;
import com.liusand.pojo.PageInfo;
import com.liusand.service.OrderService;
import com.liusand.vo.ClientOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author :liusha
 * packageName :com.liusand.controller
 * fileName :OrderController
 * creationTime :2022/12/1 20:37
 */
@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("submit")
    public Result submit(@RequestBody OrderDto orderDto){
        if(orderDto == null){
            return Result.error("提交订单失败");
        }
        boolean submitResult = orderService.submit(orderDto);
        if(!submitResult){
            return Result.error("提交订单失败");
        }
        return Result.success();
    }

    @GetMapping("userPage")
    public Result userPage(@RequestParam(value = "page",defaultValue = "1") Integer page,
                           @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){
        PageInfo<ClientOrderVo> pageInfo = orderService.userPage(page, pageSize);
        return Result.success(pageInfo);
    }
}
